//
//  BaseVModel.swift
//  TapTapSpeak
//
//  Created by liyahao on 2025/8/5.
//

import UIKit
import Combine

class BaseVModel<M: JSONable>: NSObject, ObservableObject {
    @Published var pageIndex: Int = 0
    @Published var loading: Bool = false
    @Published var isEmpty: Bool = false
    @Published var toast: String = ""
    @Published var models: [M] = []
    var cancles = Set<AnyCancellable>()
    
    override init() {
        super.init()
        self.binding()
    }
    
    func binding() {
        $toast
            .sink { Toast.toast($0) }
            .store(in: &cancles)
    }
    
    func loadData() { }
    func loadMoreData() { }
    func mockData() { }
    
    deinit {
        cancles.forEach { $0.cancel() }
    }
}
